package com.polaris.live.resp.back_resp.luckybag

import com.polaris.live.common.constant.CommonConst
import com.polaris.live.common.util.JsonUtils
import com.polaris.live.im.sfs.bean.live.ext.UserBasicVo

/**
 * LuckyBagMessageResp
 *
 * @author Created by lucas on 2024/6/11 02:23
 */
data class LuckyBagMessageResp(
    /**
     * 消息id
     */
    val messageId: Long,
    /**
     * 福袋id
     */
    val luckyBagId: Long? = null,
    /**
     * 产生消息的用户id
     */
    val userId: Long,
    /**
     * 消息类型
     */
    val messageType: Int,
    /**
     * 消息内容
     *
     * 根据消息类型解析
     */
    var content: String,
    /**
     * 创建时间
     */
    val createTime: Long,
) {

    private var _message: Any? = null

    /**
     * 直接更新消息内容
     */
    fun updateBagMessage(send: LuckyBagMessageSend) {
        _message = send
    }

    /**
     * 获取发送的消息内容
     */
    fun getBagMessage(): LuckyBagMessageSend? {
        return (_message as? LuckyBagMessageSend) ?: let {
            if (messageType == CommonConst.LuckyBagMessageType.LUCKY_BAG) {
                JsonUtils.fromJson<LuckyBagMessageSend>(content).apply {
                    this@LuckyBagMessageResp._message = this
                }
            } else {
                null
            }
        }
    }

    /**
     * 获取领取的消息内容
     */
    fun getPromptMessage(): LuckyBagMessageReceive? {
        return (_message as? LuckyBagMessageReceive) ?: let {
            if (messageType == CommonConst.LuckyBagMessageType.RECEIVE) {
                JsonUtils.fromJson<LuckyBagMessageReceive>(content).apply {
                    this@LuckyBagMessageResp._message = this
                }
            } else {
                null
            }
        }
    }

    /**
     * 获取福袋聊天消息
     */
    fun getChatMessage(): LuckyBagMessageChat? {
        return (_message as? LuckyBagMessageChat) ?: let {
            if (messageType == CommonConst.LuckyBagMessageType.LUCKY_CHAT) {
                JsonUtils.fromJson<LuckyBagMessageChat>(content).apply {
                    this@LuckyBagMessageResp._message = this
                }
            } else {
                null
            }
        }
    }

    data class LuckyBagMessageSend(
        /**
         * 发送者用户信息
         */
        val userBasic: UserBasicVo,
        /**
         * 红包大小
         */
        val coins: Long,
        /**
         * 自己是否领取
         */
        val receiveStatus: Int,
        /**
         * 炸弹数字
         */
        val bombNum: Int,
        /**
         * 状态
         *
         * 0: 领取中
         * 1: 已领取完成
         * 2: 已过期
         */
        val status: Int,
    )

    data class LuckyBagMessageReceive(
        /**
         * 所有者用户id
         */
        val ownerUserId: Long,
        /**
         * 所有者昵称
         */
        val ownerNickname: String,
        /**
         * 领取者用户id
         */
        val receiveUserId: Long,
        /**
         * 领取者用户昵称
         */
        val receiveNickname: String,
        /**
         * 炸弹状态 1中了炸弹
         */
        val bombStatus: Int,
        /**
         * 领取的金额
         */
        val coins: Long,
        /**
         * 是否领取完成
         */
        val receiveCompleted: Boolean?,
        /**
         * 领取时间
         */
        val receiveTime: Long,
    )

    data class LuckyBagMessageChat(
        /**
         * 发送者用户信息
         */
        val userBasic: UserBasicVo,
        /**
         * 消息内容
         */
        val content: String,
        /**
         * 翻译
         */
        val translationContent: String?,
    )
}